package com.ef.web.action;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;

import com.ef.constant.ConfirmMessage;
import com.ef.domain.Material;
import com.ef.service.MaterialService;
import com.ef.util.CustomExample;

public class MaterialAction extends BaseAction<Material> {

	private static final long serialVersionUID = 1L;
	private MaterialService materialService;

	protected final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
			.getLog(MaterialAction.class);

	@SuppressWarnings("serial")
	public String list() {

		this.listResult = materialService.findByExample(
				new CustomExample<Material>(this.getModel()) {

					public void appendCondition(Criteria criteria) {
						this.enableLike(MatchMode.ANYWHERE);
					}
				}, this.getStartIndex(), this.getPageSize());
		return LIST;
	}

	public String edit() {

		return EDIT;
	}

	public String save() {

		Material Material = this.getModel();
		Material.setUpdateTime(new Date());
		Material.setUpdateUser(getSessionUser());
		materialService.saveOrUpdate(Material);
		this.setResult(ConfirmMessage.Material);
		return EDIT;
	}

	public String delete() {
		String ids = getRequest().getParameter("ids");
		String[] id = ids.split(",");
		for (String i : id) {
			materialService.delete(materialService.findById(Long.valueOf(i)));
		}

		return DELETE;
	}

	public MaterialService getMaterialService() {
		return materialService;
	}

	public void setMaterialService(MaterialService materialService) {
		this.materialService = materialService;
	}
	
	

}
